<template>
	<view class="pad-lr-24">
		<view class="display-ce align-items flex-wrap mar-top-200" v-if="list.length==0">
			<image src="/static/img/icon10.png" class="proudct-item-icon-27" mode=""></image>
			<view class="mar-top-12 col-9 fontSize-30 text-align-center width-100">空空如也~~~</view>
		</view>
		<view class="pad-tb-40 pad-lr-30 radius-20 bgfff mar-top-20 display-sb align-items" v-for="item in list" :key="item.id">
			<view class="width-70 fontSize-28 col-6">
				<view class="">产品名称：<text class="col-3">{{item.brand_name}}</text></view>
				<view class="mar-top-20">机具编号：<text class="col-3">{{item.terminal_id}}</text></view>
				<view class="mar-top-20">商户名：<text class="col-3">{{item.merchant_no}}</text></view>
			</view>
				<view class="col-f fontSize-28 radius-10 fanbtn display-ce align-items" v-if="item.refund_postage_status==0" @click="refundPostage(item.id)"><text>退返邮费</text></view>
		</view>
		<!-- 满足返还条件 -->
		<tm-overlay v-model:show="showWin" contentAnimation>
			<view @click.stop="">
				<view class="popup_view radius-20 bgfff text-align-center pad-tb-40">
					<view class="fontSize-40">{{msgifo?.title}}</view>
					<view class="mar-top-40 col-6 fontSize-28">{{msgifo?.account_text}}</view>
					<view class="col-f text-align-center qry_btn radius-10" @click="_postrefundPostage">
						确认
					</view>
				</view>
			</view>
		</tm-overlay>
		<!-- 不满足返还条件 -->
		<tm-overlay v-model:show="showWinx" contentAnimation>
			<view @click.stop="">
				<view class="popup_view radius-20 bgfff text-align-center pad-tb-40">
					<view class="fontSize-40">{{msgifo?.title}}</view>
					<view class="col-6 fontSize-28 width-60" style="margin:40rpx auto 0 auto;">{{msgifo?.msg}}</view>
					<view class="col-f text-align-center qry_btn radius-10" @click="showWinx = false">
						确认
					</view>
				</view>
			</view>
		</tm-overlay>
	</view>
</template>

<script lang="ts" setup>
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import { ref } from 'vue';
import {myPos,getrefundPostage,postrefundPostage} from '../../utils/api'
onLoad(()=>{
	_myPos()
})
onReachBottom(()=>{
	if(page.value>1){
		_myPos()
	}
})
const page = ref(1)
const list = ref([])
const _myPos =() =>{
	myPos({page:page.value,limit:10}).then(res=>{
		if(res.code==1){
			list.value = list.value.concat(res.data.order.data)
			if(res.data.order.data.length>0){
				page.value++
			}
		}
	})
}
const showWin = ref(false)
const showWinx = ref(false)
const msgifo = ref()
const select_id = ref(0)
const refundPostage =(id:number)=>{
	select_id.value = id
	getrefundPostage({id:id}).then(res=>{
		if(res.code==10){
			msgifo.value = res.data
			showWinx.value = true
		}else if(res.code==11){
			msgifo.value = res.data
			showWin.value = true
		}
	})
}
const _postrefundPostage =() =>{
		postrefundPostage({id:select_id.value}).then(res=>{
			uni.showToast({
				title:res.msg,
				icon:'none'
			})
			if(res.code==1){
				list.value.forEach(item=>{
					if(item.id == select_id.value){
						item.refund_postage_status = 1
					}
				})
				showWin.value = false
			}
		})
}
</script>

<style lang="scss">
@import 'mymachine.scss';
</style>
